/**
 * \file int_eeprom.h
 * \brief Internal EEPROM driver
 * \author Radim Badsi <radim.badsi@polytech.univ-montp2.fr>
 * \date 12/07/2009
 */

#ifndef INT_EEPROM_H
#define INT_EEPROM_H

#include "smallsatos.h"

/**
  * Type of access
  */
typedef enum { 
	READ_QUERY,		/*!< Read query */
	WRITE_QUERY,	/*!< Write query */
	WIPE_QUERY		/*!< Block erase */
} ee_query_type_t;

/**
  * Structure of an EEPROM request
  */
typedef struct
{
	ee_query_type_t type;	/*!< Type of access */
	INT16U address;			/*!< Memory address (start)  */
	INT8U* value;			/*!< Data */
	INT16U size;			/*!< Size */
} eeprom_query;

/**
  * Return a pointer to the incoming EEPROM mbox
  * @return pointer to the incoming EEPROM mbox
  */
OS_EVENT* get_eeprom_query_mbox(void);

/**
  * Return a pointer to the outgoing EEPROM mbox
  * @return pointer to the outgoing EEPROM mbox
  */
OS_EVENT* get_eeprom_response_mbox(void);

/**
  * Return a pointer to the EEPROM lock (prevents the memory
  * to be accessed from several tasks at a time)
  * @return pointer to the EEPROM lock
  */
OS_EVENT* get_eeprom_lock(void);

/**
  * EEPROM driver (OS task)
  */
void eeprom_driver(void* pdata);

/**
  * Read one byte from the internal EEPROM
  * Low-level function to be used only within the driver
  * @param ad Memory address
  * @return Byte read
  */
INT8U EERead(INT16U ad);

/**
  * Write one byte to the internal EEPROM
  * Low-level function to be used only within the driver
  * @param ad Memory address
  * @param Byte to be written
  */
void EEWrite(INT16U ad, INT8U val);

/**
  * Shift the starting memory address in a request by the size
  * of the request
  * @param query EEPROM request
  */
void shift(eeprom_query* query);

#endif